package com.hz.score.cus.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hz.score.cus.model.CusInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CusInfoMapper extends BaseMapper<CusInfo> {
    @Select("select * from cus_info where biz_typ=#{bizTyp}")
    CusInfo getByBizTyp(@Param("bizTyp")String bizTyp);

    @Select("select count(1) from cus_info where parent_biz_typ=#{bizTyp}")
    int getChildsCountByBizTyp(@Param("bizTyp")String bizTyp);

    @Select("select count(1) from cus_info where parent_biz_typ is null")
    int getChildsCountIsnull();

    @Select({
            "<script>",
            "select *",
            "from cus_info",
            "where biz_typ_code in",
            "<foreach collection='bizTypCodes' item='code' open='(' separator=',' close=')'>",
            "#{code}",
            "</foreach>",
            "</script>"
    })
    List<CusInfo> getAllParent(@Param("bizTypCodes") List<String> bizTypCodes);

    @Select("select * from cus_info where biz_typ_code like concat(#{bizTypCode}, '%')")
    List<CusInfo> getAllChild(@Param("bizTypCode")String bizTypCode);
}
